package com.senlingspace.framework.security.context;

import com.senlingspace.common.utils.JwtUtilExt;
import org.apache.commons.lang3.StringUtils;

/**
 * 用户信息获取
 *
 * @author lebronjames
 */
public class SecurityUtilExt {

    /**
     * 获取会员ID
     *
     * @return
     */
    public static Long getCustomerId() {
        return SecurityContextHolderExt.getCustomerId();
    }

    /**
     * 获取会员电话
     *
     * @return
     */
    public static String getMobile() {
        return SecurityContextHolderExt.getCustomerMobile();
    }

    /**
     * 获取会员Token
     *
     * @return
     */
    public static String getToken() {
        return SecurityContextHolderExt.getToken();
    }

    /**
     * 获取token载体信息
     *
     * @return
     */
    public static JwtUtilExt.Payload getPayload() {
        String token = getToken();
        if (StringUtils.isBlank(token)) {
            return null;
        }

        return JwtUtilExt.parseToken(token);
    }

    /**
     * 获取当前门店ID
     *
     * @return
     */
    public static Long getShopId() {
        return SecurityContextHolderExt.getShopId();
    }

}
